using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace Acms.SqlDal
{
    public class UserCustomPropertyDal : Base
    {
        public enum Fields
        {
            Id,
            UserId,
            Name,
            Value
        }

        protected override void ReadRecord(Hashtable table, SqlDataReader reader)
        {
            GetReaderValue<int>(Fields.Id, reader, table);
            GetReaderValue<int>(Fields.UserId, reader, table);
            GetReaderValue<string>(Fields.Name, reader, table);
            GetReaderValue<string>(Fields.Value, reader, table);
        }

        public Hashtable[] GetAllByUserId(int userId)
        {
            SqlCommand cmd = CreateCommand("GetAllByUserId");
            AddInputParameter(cmd, "UserId", userId, SqlDbType.Int);
            return base.ExecuteGetCollection(cmd);
        }

        public void Update(ref int id, int userId, string name, string value, ref object concurencyId)
        {
            SqlCommand cmd = CreateCommand("Put");
            AddInputParameter(cmd, "UserId", userId, SqlDbType.Int);
            AddInputParameter(cmd, "Name", name, SqlDbType.VarChar, 50);
            AddInputParameter(cmd, "Value", value, SqlDbType.VarChar, 2000);
            AddInputParameter(cmd, "ConcurencyId", concurencyId, SqlDbType.Timestamp);
            AddOutputParameter(cmd, "IdOut", SqlDbType.Int);
            AddOutputParameter(cmd, "ConcurencyIdOut", SqlDbType.Timestamp);
            ExecuteCommand(cmd);
            id = GetOutputValue<int>(cmd, "IdOut");
            concurencyId = GetOutputValue<byte[]>(cmd, "ConcurencyIdOut");

        }
    }
}
